package com.zff.rental.file;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.spi.FileSystemProvider;

/**
 * 读取文件
 * 读取文件可以通过 newInputStream 方法获取输入流，然后使用 InputStream 或 BufferedReader 等类读取文件内容。
 */
public class ReadFileExample {
    public static void main(String[] args) {
        FileSystemProvider provider = FileSystems.getDefault().provider();
        Path filePath = Paths.get("example.txt");

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(provider.newInputStream(filePath)))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}